package com.lin.zoo.dao;

import com.lin.zoo.dao.Interface.IDActivity;
import com.lin.zoo.util.DataBase;

import java.sql.*;

public class ActivityDao implements IDActivity {

    private Connection con;

    private PreparedStatement state;
    @Override
    //删除活动,由饲养员调用
    public void delactivity(Object id){
        try{
            con= DataBase.getCon();
            state = con.prepareStatement("DELETE FROM activity WHERE id=?");//删除编号为id的活动数据
            state.setObject(1,id);
            state.executeUpdate();
        }catch(ClassNotFoundException | SQLException e){
            System.out.println("数据库数据调用失败" + this.getClass().getName());
        }finally{
            try{
                DataBase.close(state, con);//关闭连接
            } catch(SQLException e){
                System.out.println("连接关闭失败" + this.getClass().getName());
            }
        }
    }
    @Override
    //修改介绍
    public void setIntroduce(Object id,String introduce){
        try{
            con=DataBase.getCon();
            state = con.prepareStatement("update activity set introduce=? WHERE id=?");//将修改的数据返回数据库
            state.setObject(1,introduce);
            state.setObject(2,id);
            state.executeUpdate();
            DataBase.close(state, con);

        }catch (SQLException | ClassNotFoundException ex) {
            System.out.println("数据修改错误"+this.getClass().getName());
        }
    }
    @Override
//修改所属园区id
    public void setPark(Object id,String parkId){
        try{
            con=DataBase.getCon();
            state = con.prepareStatement("update activity set parkid=? WHERE id=?");//将修改的数据返回数据库
            state.setObject(1,parkId);
            state.setObject(2,id);
            state.executeUpdate();
            DataBase.close(state, con);

        }catch (SQLException | ClassNotFoundException ex) {
            System.out.println("数据修改错误"+this.getClass().getName());
        }
    }
    @Override
    //修改开始时间
    public void setStart(Object id,String time){
        try{
            con=DataBase.getCon();
            state = con.prepareStatement("update activity set starttime=? WHERE id=?");//将修改的数据返回数据库
            state.setObject(1,time);
            state.setObject(2,id);
            state.executeUpdate();
            DataBase.close(state, con);
        }catch (SQLException | ClassNotFoundException ex) {
            System.out.println("数据修改错误"+this.getClass().getName());
        }
    }
    @Override
    //修改结束时间
    public void setEnd(Object id,String time){
        try{
            con=DataBase.getCon();
            state = con.prepareStatement("update activity set endtime=? WHERE id=?");//将修改的数据返回数据库
            state.setObject(1,time);
            state.setObject(2,id);
            state.executeUpdate();
            DataBase.close(state, con);
        }catch (SQLException | ClassNotFoundException ex) {
            System.out.println("数据修改错误"+this.getClass().getName());
        }
    }
}
